package com.generator.mode;

import lombok.Getter;
import lombok.Setter;

import java.util.Objects;

public class HostAndPort {

    @Getter
    @Setter
    private String host;
    @Getter
    @Setter
    private int port;

    public static HostAndPortBuilder builder() {
        return new HostAndPortBuilder();
    }

    public static class HostAndPortBuilder {
        private final HostAndPort hostAndPort = new HostAndPort();

        public HostAndPortBuilder host(String host) {
            hostAndPort.setHost(host);
            return this;
        }

        public HostAndPortBuilder port(int port) {
            hostAndPort.setPort(port);
            return this;
        }

        public HostAndPort build() {
            return hostAndPort;
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        HostAndPort that = (HostAndPort) o;

        if (port != that.port) return false;
        return Objects.equals(host,that.host);
    }

    @Override
    public int hashCode() {
        int result = host != null ? host.hashCode() : 0;
        result = 31 * result + port;
        return result;
    }
}
